FROM reliableembeddedsystems/yocto:ubuntu-20.04-base
USER root
MAINTAINER jingyihome <jingyihome@163.com>


# Set the locale
ENV LANG C.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL C.UTF-8
ENV VERSION 2.3.5


# 文件权限
RUN chown -R $USER:$USER /



# 去掉网络运营商设定的缓存 -o Acquire::http::No-Cache=True
# RUN sed -i "s@/archive.ubuntu.com/@/mirrors.163.com/@g" /etc/apt/sources.list \
#     && rm -rf /var/lib/apt/lists/* \
#     && apt-get update --fix-missing -o Acquire::http::No-Cache=True

# RUN sed -i 's@/archive.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g' /etc/apt/sources.list && rm -rf /var/lib/apt/lists/*;

# Set timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime

# Install dependencies packages add --fix-missing ,update php7.4
RUN apt-get update  && apt-get -y install php7.4 php7.4-mysql php7.4-curl php7.4-zip php7.4-xml php7.4-gd supervisor git apache2 libapache2-mod-php7.4 mysql-server unzip curl net-tools wget

# Stop supervisor
RUN /etc/init.d/supervisor stop

# Add image config and scripts
RUN mkdir -p /scripts/
ADD scripts/mysql_user.sh /scripts/mysql_user.sh
ADD scripts/mysql.sh /scripts/mysql.sh
RUN chmod 755 /scripts/*.sh
ADD conf/supervisord-apache2.conf /etc/supervisor/conf.d/supervisord-apache2.conf
ADD conf/supervisord-mysqld.conf /etc/supervisor/conf.d/supervisord-mysqld.conf

# MySQL conf
RUN sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/mysql.conf.d/mysqld.cnf

# enable rewrite
RUN a2enmod rewrite
RUN sed -i '170,174s/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf

# Delete html
RUN rm -rf /var/www/html/*


# Download DzzOffice

RUN curl -o /tmp/dzzoffice-${VERSION}.tar.gz https://codeload.github.com/zyx0814/dzzoffice/tar.gz/${VERSION} \
&& tar -xzvf /tmp/dzzoffice-${VERSION}.tar.gz -C /tmp \
&& rm -rf /tmp/dzzoffice-${VERSION}.tar.gz /tmp/dzzoffice-${VERSION}/*.md \
&& mv /tmp/dzzoffice-${VERSION}/* /var/www/html/



RUN chown -R www-data:www-data /var/www/html/
RUN ln -s /var/run/mysqld/mysqld.sock  /tmp/mysqld.sock

# Port
EXPOSE 80 3306

CMD [ "/scripts/mysql.sh" ]
